#pragma once
#include <QFile>
#include <QIODevice>
#include <QString>

#include "core.h"
#include "strings/BaseString.h"

class S_CORE_EXPORT FileSys {
 public:
  static FileSys* instance();
  // directory
  QString runRootDir() const;
  QString dataDir() const;
  QString appCfgDir() const;  // file in this directory should not be changed!
  QString writeableAppCfgDir() const;
  QString logDir() const;
  QString userCfgDir() const;
  QString tmpDir() const;
  bool createFile(const QString& fullFileName, QIODevice::OpenModeFlag flag,
                  QFile*& file) const;
  bool closeFile(QFile* file) const;
  int64_t getFileSize(QFile* file) const;
  int64_t readFile(QFile* file, char* data, int64_t maxlen);
  int copyFile(const char* src, const char* des);
  bool removeFile(const QString& fullFileName) const;
  bool isFileExist(const QString& fullFileName) const;
  bool isFileWritable(const QString& fullFileName) const;
  bool makePathExist(const QString& path) const;
  qb::base::BaseString getSlashPath(const char* path);
  void makeSlashPath(qb::base::BaseString& path);

  void setUserId(const QString v) { m_userId = v; }

  std::string makeFullDataPath(const std::string& path);  // for logging

 private:
  FileSys();

  QString m_exeDir;
  QString m_appName;
  QString m_userId;
};
